var t = getApp();

Page({
    data: {
        language: "",
        isOpenCompany: !1,
        kwd: "",
        companyRadio: null,
        serial_number: "",
        storeName: "",
        insuer: "",
        certificateNumber: "",
        information: "",
        insuranceAddress: "",
        insuredProperty: "",
        usertype: "",
        amountForce: "",
        insurancePeriod: "",
        premium: "",
        insuranceTypeVal: "",
        glassRisk: "",
        insurer: "",
        companyNames: "",
        Memoinformation: "",
        insuranceTypeshow: !1,
        columns: [ {
            text: "火险+盗抢"
        }, {
            text: "单独盗抢"
        } ],
        companyList: [],
        selectCompanyPopup: !1,
        columns_ind: 0,
        id: ""
    },
    onLoad: function(t) {
        this.setData({
            id: t.id
        }), this.getJson();
    },
    getJson: function() {
        var a = this, e = t.getNetAddresss("plugin.supplier.frontend.insurance.insurance-edit"), s = {
            id: a.data.id
        };
        t._postNetWork({
            url: e,
            data: s,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    serial_number: e.data.serial_number,
                    storeName: e.data.shop_name,
                    insuer: e.data.insured,
                    certificateNumber: e.data.identification_number,
                    information: e.data.phone,
                    insuranceAddress: e.data.address,
                    insuredProperty: e.data.insured_property,
                    usertype: e.data.customer_type,
                    amountForce: e.data.insured_amount,
                    insurancePeriod: e.data.guarantee_period,
                    premium: e.data.premium,
                    insurer: e.data.insurance_company,
                    insuranceTypeVal: e.data.insurance_coverage,
                    companyRadio: e.data.company_id,
                    glassRisk: e.data.additional_glass_risk,
                    Memoinformation: e.data.note
                }), e.data.has_one_company && e.data.has_one_company.name && a.setData({
                    companyNames: e.data.has_one_company.name
                })) : wx.showToast({
                    icon: "none",
                    title: res.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    showCompany: function() {
        this.setData({
            selectCompanyPopup: !0
        });
        this.taPsearch({
            detail: {
                value: ""
            }
        });
    },
    goClockPunchRecord: function() {
        this.setData({
            selectCompanyPopup: !1
        });
    },
    bindPickerChange: function(t) {
        this.setData({
            insuranceTypeVal: this.data.columns[t.detail.value].text
        }), console.log(this.data.columns[t.detail.value]);
    },
    selectTap: function(t) {
        console.log(t), this.setData({
            companyRadio: t.currentTarget.dataset.id,
            selectCompanyPopup: !1,
            companyNames: t.currentTarget.dataset.name
        });
    },
    serial_number: function(t) {
        console.log(t), this.setData({
            serial_number: t.detail.value
        });
    },
    storeName: function(t) {
        console.log(t), this.setData({
            storeName: t.detail.value
        });
    },
    insuer: function(t) {
        console.log(t), this.setData({
            insuer: t.detail.value
        });
    },
    certificateNumber: function(t) {
        console.log(t), this.setData({
            certificateNumber: t.detail.value
        });
    },
    information: function(t) {
        console.log(t), this.setData({
            information: t.detail.value
        });
    },
    insuranceAddress: function(t) {
        console.log(t), this.setData({
            insuranceAddress: t.detail.value
        });
    },
    insuredProperty: function(t) {
        console.log(t), this.setData({
            insuredProperty: t.detail.value
        });
    },
    usertype: function(t) {
        console.log(t), this.setData({
            usertype: t.detail.value
        });
    },
    amountForce: function(t) {
        console.log(t), this.setData({
            amountForce: t.detail.value
        });
    },
    insurancePeriod: function(t) {
        console.log(t), this.setData({
            insurancePeriod: t.detail.value
        });
    },
    premium: function(t) {
        console.log(t), this.setData({
            premium: t.detail.value
        });
    },
    glassRisk: function(t) {
        console.log(t), this.setData({
            glassRisk: t.detail.value
        });
    },
    insurer: function(t) {
        console.log(t), this.setData({
            insurer: t.detail.value
        });
    },
    submit: function(a) {
        if (console.log(this.data.serial_number), t._isTextEmpty(this.data.serial_number)) this.Toast("请填写序号！"); else if (t._isTextEmpty(this.data.storeName)) this.Toast("请填写店面名称！"); else if (t._isTextEmpty(this.data.insuer)) this.Toast("请填写被保险人！"); else if (t._isTextEmpty(this.data.certificateNumber)) this.Toast("请填写证件号码！"); else if (t._isTextEmpty(this.data.information)) this.Toast("请填写被保险人联系方式！"); else if (t._isTextEmpty(this.data.insuranceAddress)) this.Toast("请填写保险地址！"); else if (t._isTextEmpty(this.data.insuredProperty)) this.Toast("请填写投保财产！"); else if (t._isTextEmpty(this.data.usertype)) this.Toast("请填写用户类型！"); else if (t._isTextEmpty(this.data.insurancePeriod)) this.Toast("请填写保险期限！"); else if (t._isTextEmpty(this.data.premium)) this.Toast("请填写保费！"); else if (t._isTextEmpty(this.data.insuranceTypeVal)) this.Toast("请选择投保险种！"); else if (t._isTextEmpty(this.data.glassRisk)) this.Toast("请输入玻璃险！"); else if (t._isTextEmpty(this.data.insurer)) this.Toast("请输入投保人"); else if (t._isTextEmpty(this.data.companyNames)) this.Toast("请选择保险公司"); else {
            var e = {
                id: this.data.id,
                data: {
                    serial_number: this.data.serial_number,
                    shop_name: this.data.storeName,
                    insured: this.data.insuer,
                    identification_number: this.data.certificateNumber,
                    phone: this.data.information,
                    address: this.data.insuranceAddress,
                    insured_property: this.data.insuredProperty,
                    customer_type: this.data.usertype,
                    insured_amount: this.data.amountForce,
                    guarantee_period: this.data.insurancePeriod,
                    premium: this.data.premium,
                    insurance_company: this.data.insurer,
                    insurance_coverage: this.data.insuranceTypeVal,
                    additional_glass_risk: this.data.glassRisk,
                    company_id: this.data.companyRadio,
                    note: this.data.Memoinformation
                }
            };
            console.log(e);
            var s = t.getNetAddresss("plugin.supplier.frontend.insurance.insurance-edit");
            t._postNetWork({
                url: s,
                data: e,
                success: function(t) {
                    var a = t.data;
                    console.log(a), 1 == a.result ? wx.showToast({
                        title: a.msg,
                        icon: "none",
                        duration: 1e3,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1e3);
                        }
                    }) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    taPsearch: function(a) {
        console.log(a);
        var e = a.detail.value, s = this, i = t.getNetAddresss("plugin.supplier.frontend.insurance.searchCompany");
        i += "&kwd=" + e, t._getNetWork({
            url: i,
            success: function(t) {
                var a = t.data;
                console.log(a), 1 == a.result ? s.setData({
                    companyList: a.data.data
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    Toast: function(t) {
        wx.showToast({
            title: t,
            icon: "none",
            duration: 1e3
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});